package com.example.app6.te;

import android.content.Context;
import android.text.Layout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import org.w3c.dom.Attr;

public class TouchEventInterceptorLayout extends LinearLayout {
//    private boolean firstRecyclerViewTouched = false;
    public TouchEventInterceptorLayout(Context context) {
        super(context);
    }

    public TouchEventInterceptorLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {

        return super.onInterceptTouchEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {

        // 获取子视图的数量
        int childCount = getChildCount();
//            // 获取子视图的位置
        float x = event.getX();
        Boolean consume=false;
//
//            // 根据触摸事件的x坐标决定哪个RecyclerView可以滑动
        if (x < getWidth() / 3) {
            consume=getChildAt(0).onTouchEvent(event);
        } else if (x >= getWidth() / 3 && x < 2 * getWidth() / 3) {
            consume=getChildAt(1).onTouchEvent(event);
        } else if (x >= 2 * getWidth() / 3) {
           consume= getChildAt(2).onTouchEvent(event);
        }

        return consume;
    }
}
